package com.study.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.study.constant.ApiRouterConstant;
import com.study.convention.result.Result;
import com.study.convention.result.Results;
import com.study.dto.req.ShortLinkCreateReqDTO;
import com.study.dto.req.ShortLinkPageReqDTO;
import com.study.dto.resp.ShortLinkCreateRespDTO;
import com.study.dto.resp.ShortLinkGroupCountQueryRespDTO;
import com.study.dto.resp.ShortLinkPageRespDTO;
import com.study.service.ShortLinkService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author canace
 * @version 1.0
 * @description 短链接控制类
 * @date 2024/1/30 20:52
 */

@RestController
@RequiredArgsConstructor
@RequestMapping(ApiRouterConstant.BASE_API_V1)
public class ShortLinkController {

    private final ShortLinkService shortLinkService;

    /**
     * 新建短链接
     *
     * @param requestParam 请求参数
     * @return 短链接信息
     */
    @PostMapping("/create")
    public Result<ShortLinkCreateRespDTO> createShortLink(@RequestBody ShortLinkCreateReqDTO requestParam) {
        return Results.success(shortLinkService.createShortLink(requestParam));
    }

    /**
     * 获取短链接分组中短链接数量
     *
     * @param requestParam 请求参数
     * @return 分组中的数量
     */
    @GetMapping("/count")
    public Result<List<ShortLinkGroupCountQueryRespDTO>> listGroupShortLinkCount(@RequestParam("requestParam") List<String> requestParam) {
        return Results.success(shortLinkService.listGroupShortLinkCount(requestParam));
    }

    /**
     * 根据分类id分页查询短链接
     *
     * @param requestParam 请求参数
     * @return 分页查询短链接返回参数
     */
    @GetMapping("/page")
    public Result<IPage<ShortLinkPageRespDTO>> getPageShortLink(ShortLinkPageReqDTO requestParam) {
        return Results.success(shortLinkService.getPageShortLink(requestParam));
    }
}
